/*
 * $Id: SqlDateConverter.java 30 2006-06-08 13:26:40Z wjx $
 */
package	com.someok.utils.datetime.converters;

import java.sql.Date;

import com.someok.utils.datetime.DateTimeStamp;
import com.someok.utils.datetime.JDateTime;

/**
 *
 *
 * <p><a href="SqlDateConverter.java.html"><i>View Source</i></a></p>
 *
 * @author wjx
 * @version $Revision: 30 $ $Date: 2006-06-08 21:26:40 +0800 (星期四, 08 六月 2006) $
 */
public class SqlDateConverter implements com.someok.utils.datetime.JdtConverter {

	public void load(JDateTime gt, Object o) {
		if (o instanceof Date) {
			Date d = (Date) o;
			gt.set(1900 + d.getYear(), d.getMonth() + 1, d.getDate());
		}
	}

	public Object get(JDateTime gt) {
		DateTimeStamp time = gt.getDateTimeStamp();
		return new Date(time.year - 1900, time.month - 1, time.day);
	}

	public void store(JDateTime gt, Object o) {
		if (o instanceof Date) {
			Date d = (Date) o;
			DateTimeStamp time = gt.getDateTimeStamp();
			d.setYear(time.year - 1900);
			d.setMonth(time.month - 1);
			d.setDate(time.day);
		}
	}

}
